export const mixins = {
	methods:{
		// 计算课程的等级，因为后端返回的数据是 0 1 2
		courseType(courseType) {
			let level = ''
			switch (courseType) {
				case 1:
				level = '初级';
				break;
				case 2:
				level = '中级';
				break;
				case 3:
				level = '高级';
				break;
			}
			return level
		},
		// 课程人数
		courseNumber(value) {
			const newValue = ['','','']
			let fr = 1000
			let num = 3
			let text1 = ''
			let fm = 1
			while (value / fr >= 1){
				fr *= 10
				num += 1
			}
			if (num <= 8) {
				text1 = parseInt(num - 4) / 3 > 1 ? '千万' : 'W'
				fm = text1 === 'W' ? 10000 : 10000000
				if (value % fm === 0) {
					newValue[0] = parseInt(value / fm) + ''
				}else {
					newValue[0] = parseInt(value / fm).toFixed(1) + ''
				}
				newValue[1] = text1
			}
			if (value < 1000) {
				newValue[0] = value + ''
				newValue[1] = ''
			}
			return newValue.join('')
		},
		// 动态计算可视区域的高度，由于在生命周期onLoad中无法获取到dom，所以是在onReady中进行获取
		getHeight(headerSearch,homeTabs,content,title) {
			let searchHeight = 0;
			let homeBarHeight = 0;
			let contentHeight = 0;
			let titleHeight = 0;
			let height = 0;
			
			if (headerSearch) {
				// 获取搜索的高度,有api可以获取dom header-search的高度
				let headerSearchDom = uni.createSelectorQuery().select(headerSearch);
				headerSearchDom.boundingClientRect(data => {
					searchHeight = data.height
				}).exec()
			}
			
			if (homeTabs) {
				// 获取home-tabs的高度
				let homeTabsDom = uni.createSelectorQuery().select(homeTabs);
				homeTabsDom.boundingClientRect(data => {
					homeBarHeight = data.height
				}).exec()
			}
			
			if (content) {
				// 获取home-tabs的高度
				let contentHeightDom = uni.createSelectorQuery().select(content);
				contentHeightDom.boundingClientRect(data => {
					contentHeight = data.height
				}).exec()
			}
			
			if (title) {
				// 获取home-tabs的高度
				let titleHeightDom = uni.createSelectorQuery().select(title);
				titleHeightDom.boundingClientRect(data => {
					titleHeight = data.height
				}).exec()
			}
			// 计算可视区域的高度
			uni.getSystemInfo({
				success(res) {
					height = res.windowHeight - searchHeight - homeBarHeight - titleHeight - contentHeight
				}
			})
			return height
		}
	}
}